package com.bilin.coin.list;

import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bilin.coin.R;
import com.bilin.coin.bean.BuyRecordBean;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.network.RequestUtils;
import com.bilin.coin.utils.DensityUtils;
import com.bilin.coin.utils.SpacesItemDecoration;
import com.bilin.coin.widget.AbsPullToRefreshRecycleView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class BuyRecordList extends AbsPullToRefreshRecycleView<BuyRecordBean.RecordsBean> {



    public BuyRecordList(BaseAppCompatActivity activity) {
        super(activity, true,false, true);
    }

    @Override
    public int fillPageSize() {
        return 15;
    }

    @Override
    public boolean isPost() {
        return false;
    }

    @Override
    public List parseListDataAndFillTotal(String dataJson) {
        BuyRecordBean productHomeBean = RequestUtils.getGson().fromJson(dataJson, BuyRecordBean.class);
        totalCount = productHomeBean.getTotal();
        return productHomeBean.getRecords();
    }

    @Override
    public Map<String, String> fillParams() {
        HashMap params = new HashMap();
        params.put("currentPage",page+"");
        params.put("pageSize",pageSize+"");
        return params;
    }

    @Override
    protected RecyclerView.LayoutManager fillLayoutManger() {
        LinearLayoutManager manager = new LinearLayoutManager(activity);
        manager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.addItemDecoration(new SpacesItemDecoration(1, DensityUtils.dp2px(activity, 15), 0x1555));
        return manager;
    }

    @Override
    public String fillUrl() {
        return "/api/buy-log/list";
    }

    @Override
    protected void convertItem(BaseViewHolder helper, BuyRecordBean.RecordsBean item) {

        helper.setText(R.id.tv_time, item.getCreateTime()+"");
        helper.addOnClickListener(R.id.tv_bt);
        TextView tv_bt = helper.getView(R.id.tv_bt);
        tv_bt.setVisibility("true".equals(item.getCanRefund())? View.VISIBLE:View.GONE);
        //设备类型 1-推车 2-小挖机 3-运煤车 4-大挖机
        switch (item.getDevice()) {
            case "1":
                helper.setText(R.id.tv_title, "推车"+"");
                break;
            case "2":
                helper.setText(R.id.tv_title, "小挖机"+"");
                break;
            case "3":
                helper.setText(R.id.tv_title, "运煤车"+"");
                break;
            case "4":
                helper.setText(R.id.tv_title, "大挖机"+"");
                break;
        }
    }

    @Override
    protected int fillAnimationType() {
        return BaseQuickAdapter.ALPHAIN;
    }

    @Override
    protected int fillItemLayout() {
        return R.layout.item_buy_record;
    }
}
